<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>canvas</title>
  <style>
    canvas {
      box-shadow: 5px 5px 10px #CCC;
    }
  </style>
</head>

<body>
  <canvas id="canvas" width="500" height="500">
    你的浏览器太low了~
  </canvas>
  <script>

    window.onload = function () {

      var canvas = document.getElementById('canvas')
      if (canvas.getContext) {
        var cvsCtx = canvas.getContext('2d');
        // 设置样式：font(style, weight, size, family)
        cvsCtx.font = 'italic bold 100px arial';
        // 设置阴影 
        cvsCtx.shadowColor = 'orange';
        cvsCtx.shadowBlur = 10;
        cvsCtx.shadowOffsetX = 15; // 偏移量 正值往下
        cvsCtx.shadowOffsetY = 15;// 偏移量 正值往右

        // 添加渐变色
        var lg = cvsCtx.createLinearGradient(0, 100, 280, 150);
        lg.addColorStop(0, '#019F62');
        lg.addColorStop(0.5, '#A7D30C');
        lg.addColorStop(1, 'red');

        cvsCtx.fillStyle = lg;
        // 绘制文字
        cvsCtx.fillText('smile', 50, 150);
      } else {
        alert('你的浏览器太low了~')
      }
    }
  </script>

</body>

</html>